/**
* @Title: orgGrading_ctrl.js
* @Description: TODO
* Copyright: Copyright (c) 2014 
 * Company:中国平安
*
* @Project HIMS-FWA
* @author EX-XIEQI001
* @date 2014年10月29日 下午4:48:14
* @version V1.0
*/
;
(function(){
	'use strict';
	var app = angular.module('fwa.mainApp');
	app.controller('OrgRuleCtrl', ['$scope','$http','$modal','BaseURL','Modal',
		                                function($scope,$http,$modal,baseUrl,Modal){
		
		  initOrgRuleInfo();
		
		
		/**
		 * 初始化医院考评规则信息
		 */
		function initOrgRuleInfo(){
			$scope.loading = true;
			var parameter={
					categoryType:'01' //医院考评规则
			             };
			 $http({
					method : 'post',
					cache : false,
					url : baseUrl + 'evaluationRule/loadEvaluationRules.do',
					params :parameter
				}).success(function(response, status, headers, config) {
					 $scope.loading =false;
					 if(response){
						    var flag=response.flag;
							var list=response.list;
							 if(flag){
								  $scope.dataList=list;
							 }else{
								 Modal.alert("加载定点医院考评规则数据失败!");
							 }
					 }
					
				});
			
			
			
		}
		
		/**
		 * 刷新当前页面的请求
		 */
		$scope.flashOrgCurrentPage=function(){
			initOrgRuleInfo();
		}
		
		/**
		 * 新增规则
		 */
		$scope.addRule=function(){
					$scope.categoryType="0"; //医院
				    var scope = $scope.$new();
					var modalInstance = $modal.open({
					      templateUrl: baseUrl+'views/hcpms/evaluation/evaluationRule/evaluationRule_addOrUpdate_view.html',
					      backdrop:'static',
						  size:'sm',
						  scope:scope,
						  controller:'evaluationRuleAddOrUpdateCtrl'
					      });
			
		}
		
		/**
		 * 编辑规则
		 */
		$scope.editorRule=function(id){
			$scope.categoryType="0"; //医院
			$scope.id=id; //医院规则id
		    var scope = $scope.$new();
			var modalInstance = $modal.open({
			      templateUrl: baseUrl+'views/hcpms/evaluation/evaluationRule/editorOrgRule_view.html',
			      backdrop:'static',
				  size:'sm',
				  scope:scope,
				  controller:'EditorOrgRuleCtrl'
			      });
	
               }
		
		
		
		/**
		 * 新增扣分设置
		 */
		$scope.addMarkScoreSet=function(scoreList,markRuleId){
			$scope.categoryType="0"; //医院
		    var scope = $scope.$new();
		        scope.scoreList=scoreList;
		        scope.markRuleId=markRuleId;
			var modalInstance = $modal.open({
			      templateUrl: baseUrl+'views/hcpms/evaluation/evaluationRule/addMarkScoreDialog.html',
			      backdrop:'static',
				  size:'sm',
				  scope:scope,
				  controller:'AddMarkScoreDialogCtr'
			      });
				
			}
		
		/**
		 * 删除规则
		 */
		$scope.deleteRule=function(){
			var selectCheckBoxItem=$("input[name='categoryCheck']:checked");
			var selectItemArray=new Array();
			
			if(selectCheckBoxItem.length>0){
				
				$.each(selectCheckBoxItem,function(index,item){
					var selectValueId=item.value;
					selectItemArray.push(selectValueId);
				});
				
				
				Modal.confirm('确认要删除吗？', function(){
					
					
					var parameter={
							categoryType:'01', //医院考评规则
							list:selectItemArray
					        };
					 $http({
							method : 'post',
							cache : false,
							url : baseUrl + 'evaluationRule/deleteEvaluationRules.do',
							params :parameter
						}).success(function(response, status, headers, config) {
							 if(response){
								    if(response.flag){
								    	initOrgRuleInfo();
								    	Modal.alert(response.msg);
								    }else{
								    	Modal.alert(response.msg);
								    }
							 }else{
								 Modal.alert("返回数据失败!");
							 }
							
						});
					
					
					
					
				});
				
				
			}else{
				Modal.alert("请选择要删除的记录!");
			}
		}
		
		
	    	
	      }]);
})();